class Solution {
public:
    int maximumSwap(int num) {
        string s = to_string(num);
        int n = s.size();
        int idx1 = 0, idx2 = 0;
        bool f = 0;
        for (int i = 0; i < n - 1; i++) {
            int ma = 0;
            for (int j = i + 1; j < n; j++) {
                if (s[i] < s[j]) {
                    int z = s[j] - '0';
                    if (ma <= z) {
                        ma = z;
                        idx2 = j;
                        f = 1;
                    }
                }
            }
            if (f) {
                idx1 = i;
                break;
            }
        }
        cout << "idx1==" << idx1 << endl;
        cout << "idx2==" << idx2 << endl;
        swap(s[idx1], s[idx2]);
        int ans = 0;
        for (auto x : s) {
            int z = x - '0';
            ans = ans * 10 + z;
        }
        return ans;

    }
};